package com.xgq.drink.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xgq.drink.entity.ChatGroup;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 聊天群组Mapper接口
 */
public interface ChatGroupMapper extends BaseMapper<ChatGroup> {
    
    /**
     * 获取用户加入的所有群组
     * @param userId 用户ID
     * @return 群组列表
     */
    @Select("SELECT g.* FROM chat_group g " +
            "JOIN chat_group_member m ON g.group_id = m.group_id " +
            "WHERE m.user_id = #{userId} AND m.status = 1")
    List<ChatGroup> getUserGroups(@Param("userId") Long userId);
    
    /**
     * 更新群组信息
     * @param groupId 群组ID
     * @param groupName 群组名称
     * @param groupAvatar 群组头像
     * @param announcement 群公告
     * @return 更新结果
     */
    @Update("UPDATE chat_group SET group_name = #{groupName}, group_avatar = #{groupAvatar}, " +
            "announcement = #{announcement}, update_time = NOW() " +
            "WHERE group_id = #{groupId}")
    int updateGroupInfo(@Param("groupId") String groupId,
                        @Param("groupName") String groupName, 
                        @Param("groupAvatar") String groupAvatar, 
                        @Param("announcement") String announcement);
    
    /**
     * 更新群组状态
     * @param groupId 群组ID
     * @param status 状态值
     * @return 更新结果
     */
    @Update("UPDATE chat_group SET status = #{status}, update_time = NOW() " +
            "WHERE group_id = #{groupId}")
    int updateGroupStatus(@Param("groupId") Long groupId, @Param("status") Integer status);
} 